package com.zk.ppa.controller;

import com.zk.ppa.commom.result.Result;
import com.zk.ppa.commom.result.ResultCode;
import com.zk.ppa.dao.po.Family;
import com.zk.ppa.dao.po.FamilyMembers;
import com.zk.ppa.service.FamilyMemberService;
import com.zk.ppa.service.FamilyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Mr.yang
 * @create 2021-03-24 22:26
 */
@Api(tags = "贫困户信息录入相关接口")
@CrossOrigin
@RequestMapping("/Family")
@RestController
public class FamilyController {
    @Autowired
    private FamilyService familyService;


    //保存贫困户基本信息
    @ApiOperation(value = "保存贫困户的基本信息")
    @PostMapping("/saveFamily")
    public Result<Family> saveFamily(@RequestBody Family family){
        return  familyService.saveFamily(family)? Result.SUCCESS().setData(family).setMessage("贫困户信息保存成功") : Result.FAIL("贫困户信息保存失败");
    }

    //查找所有贫困户的基本信息
    @ApiOperation(value = "查找所有贫困户的基本信息")
    @GetMapping("/getFamily")
    public Result<Family> getFamily(){
        List<Family> familyList = familyService.getFamily();
        if(familyList != null){
            return Result.SUCCESS().setData(familyList).setMessage("贫困户的所有信息获取成功");
        } else {
            return Result.FAIL("贫困户的所有信息获取失败");
        }
    }

    //查找某个贫困的基本信息
    @ApiOperation(value = "查找某个贫困的基本信息")
    @GetMapping("/getFamilyById")
    public Result<Family> getFamilyById(@RequestBody long id){
        Family family = familyService.getFamilyById(id);
        if (family != null){
            return Result.SUCCESS().setData(family).setMessage("该贫困户的基本信息获取成功");
        } else {
            return Result.FAIL("该贫困户的基本信息获取失败");
        }
    }

    //更改某个贫困户的基本信息
    @ApiOperation(value = "更改某个贫困户的基本信息")
    @GetMapping("/updateFamily")
    public Result<Family> updateFamily(@RequestBody Family family){
        return familyService.updateFamily(family)?Result.SUCCESS().setMessage("贫困户的基本信息更改成功"):Result.FAIL("贫困户的基本信息更改失败");
    }

    //删除某个贫困户的基本信息
    @ApiOperation(value = "删除某个贫困户的基本信息")
    @GetMapping("/deleteFamily")
    public Result<Family> deleteFamily(@RequestBody long id){
        return familyService.deleteFamily(id)?Result.SUCCESS().setMessage("贫困户的基本信息删除成功"):Result.FAIL("贫困户的基本信息删除失败");
    }
}
